package com.woniu.controller;

import com.woniu.pojo.Clazz;
import com.woniu.pojo.Interview;
import com.woniu.pojo.PageBean;
import com.woniu.pojo.Student;
import com.woniu.service.ClazzService;
import com.woniu.service.InterviewService;
import com.woniu.service.StudentService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.*;

@Controller
@RequestMapping("interview")
public class InterviewController{
    @Resource
    private  InterviewService interviewService;
    @Resource
    private StudentService studentService;
    @Resource
    private ClazzService clazzService;
    //点击技术面试后跳转页面
    @RequestMapping("allStudentInterviewList")

    public String allStudentInterviewList(Model model){
        List<Clazz> clazzList=new ArrayList<>();

        clazzList= studentService.selectStudentClazz();


        model.addAttribute("clazzList",clazzList);
        return "interview/allStudentInterviewList";
        }
    //跳转页面后，能显示学生的列表并且有对面试情况的查看，可以选择面试学生
    @RequestMapping("allStudentInterviewListDo")
    @ResponseBody
    public Map<String,Object> allStudentInterviewListDo(PageBean pageBean,Student student){
        Map<String,Object> resultMap=new HashMap<>();
           try {
            List<Student> studentList=studentService.getStudentsByPage(pageBean,student);
            if(studentList.size()==0){resultMap.put("studentList",null);}
            else {resultMap.put("studentList",studentList);}
            resultMap.put("pageBean",pageBean);
            resultMap.put("result",true);
        }catch (Exception e){
            resultMap.put("result",false);
        }
        return  resultMap;
    }
    //跳转到添加面试页面
    @RequestMapping("addInterview")
    public  String addInterview(Integer sid,Model model){

     Student student=   studentService.selectStudent(sid);
        model.addAttribute("student",student);
        model.addAttribute("sid",sid);
        return "interview/addInterview";
    }
    //添加面试
    @RequestMapping("addInterviewDo")
    @ResponseBody
    public Map<String,Object> addInterviewDo(Interview interview){
        Map<String,Object> resultMap=new HashMap<>();
        try{
            interviewService.addInterview(interview);
            resultMap.put("result",true);
        }catch (Exception e){
            resultMap.put("result",false);
        }
        return  resultMap;
    }
    //删除面试
    @RequestMapping("deleteinterviewByInoDo")
    @ResponseBody
    public Map<String,Object> deleteinterviewByInoDo(Integer ino){
        Map<String,Object> resultMap=new HashMap<>();
        try{
            interviewService.deleteinterviewByIno(ino);
            resultMap.put("result",true);
        }catch (Exception e){
            resultMap.put("result",false);
        }
        return  resultMap;
    }
    //点击面试按钮，跳转至新页面,新页面负责添加新面试信息并且能够展示已经面试过的信息
    //展示该学生以前面试
    @RequestMapping("interviewListDo")
    @ResponseBody
    public  Map<String,Object> interviewListDo(Integer sid,PageBean pageBean){
        Map<String,Object> resultMap=new HashMap<>();
        try{
            Student student=studentService.selectStudent(sid);
            List<Interview> interviewList= interviewService.InterviewListBySid(sid,pageBean);
            resultMap.put("interviewList",interviewList);
            resultMap.put("pageBean",pageBean);
            resultMap.put("result",true);
        }catch (Exception e){
            resultMap.put("result",false);
        }
      return resultMap;
    }
    @RequestMapping("htinterviewListDo")
    @ResponseBody
    public  Map<String,Object> htinterviewListDo(Integer sid,PageBean pageBean){
        Map<String,Object> resultMap=new HashMap<>();
        try{
            Student student=studentService.selectStudent(sid);
            List<Interview> interviewList= interviewService.InterviewListBySid(sid,pageBean);
            resultMap.put("interviewList",interviewList);
            resultMap.put("pageBean",pageBean);
            resultMap.put("result",true);
        }catch (Exception e){
            resultMap.put("result",false);
        }
        return resultMap;
    }
}
